package com.crm.miaohe.mapper;

import com.crm.miaohe.model.TblAuthUser;
import com.crm.miaohe.model.TblAuthUserExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TblAuthUserMapper {
    long countByExample(TblAuthUserExample example);

    int deleteByExample(TblAuthUserExample example);

    @Delete({
        "delete from tbl_auth_user",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into tbl_auth_user (username, phone_number, ",
        "password, role_id, ",
        "login_failed_count, login_locked, ",
        "login_unlock_time, account_locked, ",
        "deleted, create_time, ",
        "create_user, update_time, ",
        "update_user, version)",
        "values (#{username,jdbcType=VARCHAR}, #{phoneNumber,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{roleId,jdbcType=BIGINT}, ",
        "#{loginFailedCount,jdbcType=INTEGER}, #{loginLocked,jdbcType=BIT}, ",
        "#{loginUnlockTime,jdbcType=TIMESTAMP}, #{accountLocked,jdbcType=BIT}, ",
        "#{deleted,jdbcType=BIT}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{createUser,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{updateUser,jdbcType=VARCHAR}, #{version,jdbcType=BIGINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(TblAuthUser record);

    int insertSelective(TblAuthUser record);

    List<TblAuthUser> selectByExample(TblAuthUserExample example);

    @Select({
        "select",
        "id, username, phone_number, password, role_id, login_failed_count, login_locked, ",
        "login_unlock_time, account_locked, deleted, create_time, create_user, update_time, ",
        "update_user, version",
        "from tbl_auth_user",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.crm.miaohe.mapper.TblAuthUserMapper.BaseResultMap")
    TblAuthUser selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") TblAuthUser record, @Param("example") TblAuthUserExample example);

    int updateByExample(@Param("record") TblAuthUser record, @Param("example") TblAuthUserExample example);

    int updateByPrimaryKeySelective(TblAuthUser record);

    @Update({
        "update tbl_auth_user",
        "set username = #{username,jdbcType=VARCHAR},",
          "phone_number = #{phoneNumber,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "role_id = #{roleId,jdbcType=BIGINT},",
          "login_failed_count = #{loginFailedCount,jdbcType=INTEGER},",
          "login_locked = #{loginLocked,jdbcType=BIT},",
          "login_unlock_time = #{loginUnlockTime,jdbcType=TIMESTAMP},",
          "account_locked = #{accountLocked,jdbcType=BIT},",
          "deleted = #{deleted,jdbcType=BIT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "create_user = #{createUser,jdbcType=VARCHAR},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "update_user = #{updateUser,jdbcType=VARCHAR},",
          "version = #{version,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(TblAuthUser record);
}